<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of SaldoPiutangRekap
 *
 * @author miyzan
 */
class SaldoPiutangRekap extends MY_FPDF {
    function getthbl($thbl) {
        $th = substr($thbl, 0, 4);
        $bl = substr($thbl, 4, 2);
        if ($bl == '01')
            $bl = 'Januari';
        else if ($bl == '02')
            $bl = 'Februari';
        else if ($bl == '03')
            $bl = 'Maret';
        else if ($bl == '04')
            $bl = 'April';
        else if ($bl == '05')
            $bl = 'Mei';
        else if ($bl == '06')
            $bl = 'Juni';
        else if ($bl == '07')
            $bl = 'Juli';
        else if ($bl == '08')
            $bl = 'Agustus';
        else if ($bl == '09')
            $bl = 'September';
        else if ($bl == '10')
            $bl = 'Oktober';
        else if ($bl == '11')
            $bl = 'Nopember';
        else if ($bl == '12')
            $bl = 'Desember';
        return $bl . ' ' . $th;
    }
    
    function Header() {
       
//Logo
        $this->Image($this->logourl, 3, 3, 15);

//Arial bold 15
        $this->SetFont('Arial', 'B', 12);
        $this->SetTextColor(1, 50, 155);
        $this->SetY(8);
        $this->Cell(13);
        $this->Cell(70, 5, $this->namasekolah, 0);
        $this->Cell(117, 5, '',0);
        $this->Ln(5);
        $this->SetFont('Arial', 'B', 8);
        $this->Cell(13);
        $this->Cell(70, 3, $this->alamat,0);        
        
        
        $this->SetFont('Arial', 'I', 8);
        $this->SetY(8);
        $this->Cell(157);
        $this->Cell(20, 3, 'Tanggal Cetak', 0, 0, 'L');
        $this->Cell(3, 3, ':', 0, 0, 'C');
        $this->Cell(20, 3, date('d/m/Y'), 0, 0, 'R');
        $this->Ln(3);
        $this->Cell(157);
        $this->Cell(20, 3, 'Waktu Cetak', 0, 0, 'L');
        $this->Cell(3, 3, ':', 0, 0, 'C');
        $this->Cell(20, 3, date('h:i:s'), 0, 0, 'R');
        $this->Ln(3);
        $this->Cell(157);
        $this->Cell(20, 3, 'Halaman', 0, 0, 'L');
        $this->Cell(3, 3, ':', 0, 0, 'C');
        $this->Cell(20,3, $this->PageNo() . ' dari {nb}', 0, 0, 'R');
//        $this->Ln();
        $this->SetDrawColor(1, 50, 155);
        $this->SetLineWidth(.25);
        $this->Line(5, 19, 205, 19);
        
        $this->Ln(6);
        
        $this->SetTextColor(0, 0, 0);
        $this->SetX(5);
        $this->SetFont('Arial', 'B', 10);
        $this->Cell(0, 5, 'REKAP SALDO PIUTANG SISWA', 0, 0, 'C');
        $this->Ln();
        $this->SetX(5);
        $this->SetFont('Arial', '', 10);
        if(count($this->dataheader)>0){
            $this->Cell(0, 5, $this->dataheader[0], 0, 0, 'C');        
        }else{
            $this->Cell(0, 5, '', 0, 0, 'C');        
        }
        
        $this->Ln(10);
    }
    public function set_header_column($w) {
//        nis,nama,kd_kelas,kelas,kd_biaya,biaya,biaya_dasar,biaya_dikenakan
        $head = array('No', 'Tahun Ajaran', 'Semester', 'Thbl Tagihan', 'Total Biaya','Pelunasan','Sisa Biaya');
        $alignhead=array( 'C', 'C', 'C', 'C', 'C', 'C', 'C');
        $borderhead=array( 'TBL', 'TBL', 'TBL', 'TBL', 'TBL', 'TBL',1);
        $this->SetFont('Arial', 'B', 8);
        $this->SetX(5);
//        $this->RowHead($head, $w, $alignhead, $this->lineh, 0, 
//                0, 0, array(0,1,2,3,4,5,6,7,8), FALSE, NULL, $borderhead);
        for($i=0;$i<count($w);$i++){
            $this->Cell($w[$i], 4, $head[$i], $borderhead[$i], 0,$alignhead[$i]);
        }
        $this->Ln();
    } 
    function getcount_data($data,$nis){
        $total=0;
        foreach ($data as $value) {
            if($value->nis == $nis){
                $total++;
                }
        }
        return $total;
    }
    public function create_pdf($data){
        $this->AddPage();
        $this->SetAutoPageBreak(true,18);
        $w=array(8,25,25,30,25,25,25);
        $al=array('R','C', 'C', 'C', 'R','R', 'R');
        $this->SetWidths($w);
        $this->SetAligns($al);
        $this->lineh=4;
//        $this->set_header_column($w);
        $kelas='';
        $nis='';
        $jenis='';
        $number=0;
        $thbl=0;
        $totalbiaya=0;
        $totallunas=0;
        $totalsaldo=0;
        $totalcount=0;
        $reccount=0;
        foreach ($data as $v) {
          
            if($v->nis !== $nis)
            {
                $this->Ln();
                $totalbiaya=0;
                $totallunas=0;
                $totalsaldo=0;
                $number=0;
                $reccount=0;
                $nis=$v->nis;
                $totalcount=0;
                $totalcount=  $this->getcount_data($data, $v->nis);
                    
                $this->CheckPageBreak($this->lineh+8,false);
                $this->SetFont('Arial', 'B', 8);
                $this->SetX(5);
                $this->Cell(200, $this->lineh,$v->nis.' - '.$v->nama, 0, 0, 'L', false);
                
                
                $this->Ln();
                $this->set_header_column($w);
//                $this->set_header_column($w);
//                $this->SetLineWidth(.25);
//                $this->Line(5, $this->GetY()+$this->lineh, 40, $this->GetY()+$this->lineh);
//                $this->Ln();
            }
                        
            $number++;
            $reccount++;
            
            $totalbiaya +=$v->jumlah_biaya;
                $totallunas +=$v->jumlah_pelunasan;
                $totalsaldo +=$v->jumlah_sisa;
                
            $this->SetFont('Arial', '', 8);
//            nis,nama,kd_kelas,kelas,kd_biaya,biaya,biaya_dasar,biaya_dikenakan
            $this->RowHead(
                        array(                            
                            $number,                                                        
                            $v->tahun_ajaran,
                            $v->semester,                            
                            $v->thbl,
                            $v->jumlah_biaya,
                            $v->jumlah_pelunasan,
                            $v->jumlah_sisa
                        ),
                        $w,
                        $al,   
                        $this->lineh,0,1,1,array(0,1,2,3,4,5,6),true,array(2,4,5,6)
//                     3,0,1,'T',array(5,6,7)
                    );
            if ($reccount == $totalcount){
                $arrtotal=array('','','','Total',$totalbiaya,$totallunas,$totalsaldo);
                    $borderhead=array( 0, 0, 0, 'TBL', 'TBL', 'TBL',1);
                    $this->SetFont('Arial', 'B', 8);
                    $this->SetX(5);            
                    for($i=0;$i<count($w);$i++){
                        $this->Cell($w[$i], 4, (is_numeric($arrtotal[$i]))?number_format($arrtotal[$i]):$arrtotal[$i], $borderhead[$i], 0,$al[$i]);
                    }
                    $this->Ln();
            }
        }
    }
}

?>
